<template>
  <div class="app-container">
    <div class="header">
      <span>
        当前运行中的任务:
        <em>{{ avaliableJob.length }}</em>
      </span>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="用户ID" align="center" prop="xhs_user_id"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="nick_name" show-overflow-tooltip>
      </el-table-column>
      <!-- <el-table-column label="导入时间" align="center" prop="create_time" show-overflow-tooltip>
      </el-table-column> -->
      <el-table-column align="center" prop="status" label="执行状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">发送消息中</el-tag>
          <el-tag v-else type="warning">已停止</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="上次消息发送时间" align="center" prop="message_time" >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.message_time | time }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop="device_ids" label="执行设备">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.device_ids && scope.row.device_ids != 0" type="success">{{ scope.row.device_ids }}</el-tag>
          <el-tag v-else type="success">全部设备</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
            <el-popover width="160" :ref="`popover-${scope.$index}`">
              <p class="tac">您确定删除吗？</p>
              <div class="tac m0">
                <el-button type="text" size="mini" @click="scope._self.$refs[`popover-${scope.$index}`].doClose()">
                  取消
                </el-button>
                <el-button
                          type="primary"
                          size="mini"
                          @click="removeXhsUser(scope.row.xhs_user_id);scope._self.$refs[`popover-${scope.$index}`].doClose()"
                        >确定</el-button>
              </div>
              <el-button slot="reference" type="danger" icon="el-icon-delete" circle size="mini" />
            </el-popover>
         </template>
      </el-table-column>
    </el-table>

    <!-- <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400">
    </el-pagination> -->
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  filters: {
    statusFilter(status) {
      return status ? "success" : "gray";
    }
  },
  data() {
    return {
      visible: false,
      list: [],
      listLoading: true
    };
  },
  computed: {
    avaliableJob() {
      return this.list.filter(i => !!i.status);
    }
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      request({
        url: "/xhsUser/get_xhsUser_list",
        method: "get",
        params: {}
      }).then(res => {
        this.list = res.data.xhsUser;
        this.listLoading = false;
      });
    },
    removeXhsUser(id) {
      this.listLoading = true;
      request({
        url: "/xhsUser/remove_xhsUser",
        method: "post",
        data: { xhs_user_id: id }
      })
        .then(res => {
          this.fetchData();
        })
        .finally(() => {
          this.listLoading = false;
        });
    }
  }
};
</script>

<style scoped>
.header {
  font-weight: 600;
  font-size: 16px;
  color: #909399;
  display: flex;
  padding: 5px 0;
  justify-content: space-between;
  margin-bottom: 10px;
}
</style>
